package com.example.ShoppingManagementSystem.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;

@Setter
@Getter
@Data
@Entity
@Table(name = "purchasehistory")
@EntityListeners(AuditingEntityListener.class)

public class PurchaseHistory {

    @Id
    @Column(name = "PurchaseID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    int PurchaseId;

    @Column(name = "UserID")
    int userID;

    @Column(name = "ProductID")
    int ProductID;

    @Column(name = "PurchaseDate")
    @CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    Date PurchaseDate;

    @Column(name = "Quantity")
    int Quantity;

    @Column(name = "TotalPrice")
    double TotalPrice;

    public PurchaseHistory() {
    }

    public PurchaseHistory(int purchaseId, int productID, Date purchaseDate, int quantity, double totalPrice) {
        PurchaseId = purchaseId;
        ProductID = productID;
        PurchaseDate = purchaseDate;
        Quantity = quantity;
        TotalPrice = totalPrice;
    }
}
